package com.sws.common.utils.access_tokenutil.config;


import com.sws.common.utils.access_tokenutil.util.AccessTokenUtil;
import com.sws.common.utils.access_tokenutil.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 访问令牌配置类
 * 用于初始化AccessTokenUtil工具类
 */
@Component
public class AccessTokenConfig implements CommandLineRunner {

    @Autowired
    private RedisUtil redisUtil;
    
    @Value("${token.default.username}")
    private String defaultUsername;
    
    @Value("${token.default.password}")
    private String defaultPassword;

    @Value("${access-token.default-device-ip}")
    private String defaultDeviceIp;
    
    @Autowired(required = false)
    private AccessTokenUtil.DeviceIpResolver deviceIpResolver;

    public RedisUtil getRedisUtil() {
        return redisUtil;
    }

    public void setRedisUtil(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    public String getDefaultUsername() {
        return defaultUsername;
    }

    public void setDefaultUsername(String defaultUsername) {
        this.defaultUsername = defaultUsername;
    }

    public String getDefaultPassword() {
        return defaultPassword;
    }

    public void setDefaultPassword(String defaultPassword) {
        this.defaultPassword = defaultPassword;
    }

    public String getDefaultDeviceIp() {
        return defaultDeviceIp;
    }

    public void setDefaultDeviceIp(String defaultDeviceIp) {
        this.defaultDeviceIp = defaultDeviceIp;
    }
    
    public AccessTokenUtil.DeviceIpResolver getDeviceIpResolver() {
        return deviceIpResolver;
    }
    
    public void setDeviceIpResolver(AccessTokenUtil.DeviceIpResolver deviceIpResolver) {
        this.deviceIpResolver = deviceIpResolver;
    }

    /**
     * 应用启动后初始化AccessTokenUtil工具类
     */
    @Override
    public void run(String... args) {
        System.out.println("正在初始化AccessTokenUtil工具类： defaultUsername值为：" +defaultUsername +"  defaultPassword 值为：   "  + defaultPassword+ "  defaultDeviceIp值为 ： " +defaultDeviceIp);
        // 初始化AccessTokenUtil工具类
        AccessTokenUtil.init(redisUtil, defaultUsername, defaultPassword, defaultDeviceIp);
    }
} 